package com.guigu.qingcheng.orderservice.controller;


import com.guigu.qingcheng.orderservice.service.TbOrderLogService;
import com.guigu.qingcheng.pojo.order.TbOrderLog;
import com.guigu.qingcheng.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@RestController
@RequestMapping("tborderlog")
public class TbOrderLogController {
    @Autowired
    private TbOrderLogService tbOrderLogService;

    @GetMapping("findById")
    public R findById (String id) {
        TbOrderLog tbOrderLog = tbOrderLogService.getById(id);
        if (tbOrderLog  == null)
            return R.error();
        return R.ok().data("tbOrderLog",tbOrderLog);
    }


    @GetMapping("findByOrderId")
    public R findByOrderId (String id) {
        return tbOrderLogService.findByOrderId(id);
    }

    @GetMapping("findByOrderTime")
    public R findByOrderTime (String id, String status) {
        return tbOrderLogService.findByOrderTime(id,status);
    }

    //查询分页查询
    @PostMapping("findPage")
    public R findPage (@RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestBody(required = false) Map<String,Object> searchMap ) {
        return tbOrderLogService.findPage(page, size, searchMap);
    }

    //新增
    @PostMapping("add")
    public R add (@RequestBody TbOrderLog tbOrderLog) {
        boolean save = tbOrderLogService.save(tbOrderLog);
        if (save)
            return R.ok();
        return R.error();
    }

    //修改
    @PostMapping("update")
    public R update (@RequestBody TbOrderLog tbOrderLog) {
        boolean save = tbOrderLogService.updateById(tbOrderLog);
        if (save)
            return R.ok();
        return R.error();
    }

    //删除
    @GetMapping("delete")
    public R delete (String id) {
        boolean save = tbOrderLogService.removeById(id);
        if (save)
            return R.ok();
        return R.error();
    }
}

